<?php

class Model_owner extends CI_Model{
	function __construct(){
        parent::__construct();
	}	
	
	function getDataComp($nama, $telp){
		$this->db->select("owner_name, owner_telp, jenis");
		$this->db->from("owner");
		$this->db->where("owner_name", $nama);
		$this->db->where("owner_telp", $telp);
		$this->db->where("jenis", $this->input->post("jenis", true));
		$query = $this->db->get();
		if($query->num_rows() > 0){
			return false;
		}
		else{
			return true;	
		}
	}
	
	function addOwner(){
		$data = array(
		   'owner_name' => $this->input->post("nama",true) ,
		   'owner_telp' => $this->input->post("telp",true) ,
		   'alamat' => $this->input->post("alamat",true),
		   'email' => $this->input->post("email",true),
		   'interest' => $this->input->post("interest",true),
		   'adminfee' => $this->input->post("fee",true) ,
		   'jenis' =>$this->input->post("jenis",true)  
		   
		);
		$this->db->insert('owner', $data); 
		$id = $this->db->insert_id('owner', $data);
		if($this->input->post("jenis",true)=="leasing"){
			$nid = "LSG" . $id;
		}
		else{
			$nid = "AGC" . $id;
		}
		$data = array(
			'nio' => $nid
		);
		$this->db->where("owner_id",$id);
		$this->db->update('owner', $data); 
	
	}
	
	function getDriverList(){
		$this->db->select("*");
		$this->db->from("driver");
		$query = $this->db->get();
		if($query->num_rows() > 0){
			$data = array();
			$res = $query->result_array();
			foreach ($res as $hasil){
				$data[] = $hasil;
			}
			return $data;
		}else{
			return array();
		}
	}	
	
	function getDriverDet($id){
		$this->db->select("*");
		$this->db->from("driver");
		$this->db->where("driver_id",$id);
		$query = $this->db->get();
		if($query->num_rows()>0){
			$hasil = $query->result_array();
			return $hasil;
		}
	}
	
	function editDriver($id){			
		$tgllahir = $this->input->post("thn", true). "-" . $this->input->post("bln", true) . "-" . $this->input->post("tgl", true);		
		$data = array(
		   'name' => $this->input->post("nama_supir",true) ,
		   'telp' => $this->input->post("no_telp",true) ,
		   'alamat' => $this->input->post("alamat",true),
		   'no_ktp' => $this->input->post("no_ktp",true),
		   'umur' => $this->input->post("umur",true) ,
		   'gaji' =>$this->input->post("gaji",true),
		   'kategori' => $this->input->post("kategori",true) ,
		   'status' => $this->input->post("status",true) ,
		   'namabel' => $this->input->post("namabel",true),
		   'tempatlahir' => $this->input->post("temlahir",true),
		   'tanggallahir' => $tgllahir ,
		   'telprumah' =>$this->input->post("gaji",true),
		   'email' => $this->input->post("email",true),
		   'emerkontak' => $this->input->post("emerkontak",true) ,
		   'emertelp' =>$this->input->post("emertelp",true)	 		   
		);		
		$this->db->where('driver_id', $id);
		$this->db->update('driver', $data);  	
	}
	
	function delDataDriver($id){
		$this->db->where('driver_id', $id);
		$this->db->delete('driver'); 
	}
}